package com.aoxin.controller.course.webCourse;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.aoxin.model.SlfActivityRule;
import com.aoxin.service.inter.course.webCourse.ActivityRuleService;
import com.aoxin.util.AjaxRes;
import com.aoxin.util.Const;
import com.aoxin.util.ThreadLocalUtil;
import com.aoxin.util.enumerate.OperateType;
import com.aoxin.util.log.LogInfo;

@ResponseBody
@Controller
@RequestMapping("/web/activityRule")
public class ActivityRuleController {

	@Autowired
	private ActivityRuleService slfActivityRuleService;

	/**
	 * 添加活动规则
	 *
	 * @param slfActivityRule
	 * @param ajaxRes
	 */
	@RequestMapping("/insertSlfActivityRule")
	@LogInfo(operateType = OperateType.INSERT, content = "添加活动规则")
	public AjaxRes insertSlfActivityRule(SlfActivityRule slfActivityRule, AjaxRes ajaxRes) {
		Integer id = ThreadLocalUtil.getEmployee().getEmployeeId();
		String name = ThreadLocalUtil.getEmployee().getName();
		slfActivityRule.setEmployeeId(id);
		slfActivityRule.setEmployeeName(name);
		try {
			if (slfActivityRule != null) {
				Integer integer = slfActivityRuleService.insertSlfActivityRule(slfActivityRule);
				if (integer != 0 && id != 0) {
					ajaxRes.setSucceed(integer, Const.SAVE_SUCCEED);
				}
			}
		} catch (Exception e) {
			ajaxRes.setSucceed("insertSlfActivityRule Failure");
			e.printStackTrace();
		}
		return ajaxRes;
	}

	/**
	 * 批量删除活动规则
	 *
	 * @param activityRuleId
	 * @param ajaxRes
	 */
	@RequestMapping("/deleteSlfActivityRule")
	@LogInfo(operateType = OperateType.DELETE, content = "删除活动规则")
	public AjaxRes deleteSlfActivityRule(@RequestParam("activityRuleId") List<Integer> activityRuleId, AjaxRes ajaxRes) {
		try {
			Integer integer = this.slfActivityRuleService.deleteSlfActivityRule(activityRuleId);
			if (integer != 0) {
				ajaxRes.setSucceed(Const.DEL_SUCCEED);
			}
		} catch (Exception e) {
			ajaxRes.setSucceed("deleteSlfactivityRule Failure");
			e.printStackTrace();
		}
		return ajaxRes;
	}

	/**
	 * 修改活动规则
	 *
	 * @param slfActivityRule
	 * @param ajaxRes
	 */
	@RequestMapping("/updateSlfActivityRule")
	@LogInfo(operateType = OperateType.UPDATE, content = "修改活动规则")
	public AjaxRes updateSlfActivityRule(SlfActivityRule slfActivityRule, AjaxRes ajaxRes) {
		try {
			Integer integer = this.slfActivityRuleService.updateSlfActivityRule(slfActivityRule);
			if (integer != 0) {
				ajaxRes.setSucceed(Const.UPDATE_SUCCEED);
			}
		} catch (Exception e) {
			ajaxRes.setSucceed("updateSlfActivityRule Failure");
			e.printStackTrace();
		}
		return ajaxRes;
	}

	/**
	 * 活动查询条件规则
	 *
	 * @param slfActivityRule
	 * @param ajaxRes
	 * @return
	 */
	@RequestMapping("/getSlfActivityRule")
	@LogInfo(operateType = OperateType.QUERY, content = "查询活动规则")
	public AjaxRes getSlfActivityRule(SlfActivityRule slfActivityRule, AjaxRes ajaxRes) {
		try {
			List<SlfActivityRule> slfActivityRules = slfActivityRuleService.getSlfActivityRule(slfActivityRule);
			ajaxRes.setSucceed(slfActivityRules, Const.DATA_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	/**
	 * 查询所有活动规则
	 * 
	 * @param ajaxRes
	 * @return
	 */
	@RequestMapping("/getBySlfActivityRule")
	@LogInfo(operateType = OperateType.QUERY, content = "查询所有活动规则")
	public AjaxRes getBySlfActivityRule(SlfActivityRule slfActivityRule, AjaxRes ajaxRes) {
		try {
			List<SlfActivityRule> slfActivityRules = slfActivityRuleService.getBySlfActivityRule(slfActivityRule);
			ajaxRes.setSucceed(slfActivityRules, Const.DATA_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
}